package com.samapp.base;

import android.app.Activity;
import android.app.ProgressDialog;
import android.widget.Toast;

/**
 * 定义Activity基本方法
 * 
 * @author Dragon
 * @version 20160611
 */
public class BaseActivity extends Activity {

	private Toast mToast;
	private ProgressDialog loadingDialog;

	/**
	 * 显示一个Toast类型的消息
	 * 
	 * @param msg
	 *            显示的消息
	 */
	public void showToast(String msg) {
		if (mToast == null) {
			mToast = Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT);
		}
		mToast.setText(msg);
		mToast.show();
	}

	/**
	 * 显示Toast类型的消息
	 * 
	 * @param strResId
	 *            字符串资源id
	 */
	public void showToast(int strResId) {
		if (mToast == null) {
			mToast = Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT);
		}
		mToast.setText(strResId);
		mToast.show();
	}

	/**
	 * 显示loading
	 */
	public void showLoadingDialog(String str) {
		if (loadingDialog == null) {
			loadingDialog = new ProgressDialog(this);
			loadingDialog.setMessage(str);
			loadingDialog.setCanceledOnTouchOutside(false);
			loadingDialog.show();
		} else if (!loadingDialog.isShowing()) {
			loadingDialog.show();
		}
	}

	/**
	 * 取消显示loading
	 */
	public void dismissLoadingDialog() {
		if (loadingDialog != null) {
			loadingDialog.dismiss();
		}
		loadingDialog = null;
	}
}
